﻿using System;
using System.Collections.Generic;
using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;


namespace TestDxfDocument
{
    class TurningToolsWithCarbideTips
    {
        public static void TurningToolNo2BentDesign(Dictionary<string, Object> data)        //2号车刀弯曲设计
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线

            double pi = Math.PI;

            double lf = Convert.ToDouble(data["lf"]);
            double wf = Convert.ToDouble(data["wf"]);
            double h = Convert.ToDouble(data["h"]);
            double b = Convert.ToDouble(data["b"]);
            double kapr = Convert.ToDouble(data["kapr"]);
            string path = Convert.ToString(data["path"]);

            double k = kapr * pi / 180;
            Vector2 p0 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 p4 = new Vector2(p0.X + wf - b * Math.Sin(k), p0.Y - lf);
            Vector2 p1 = fun.Polar(p4, pi - k, p4.X / Math.Cos(k));
            Vector2 p2 = fun.Polar(p4, pi - k, (wf - b * Math.Sin(k)) * 0.5);
            Vector2 p3 = fun.Polar(p4, pi - k, (wf - b * Math.Sin(k)) * 0.35);
            Vector2 p5 = fun.Polar(p4, pi / 2 - k, b);
            Vector2 p6 = fun.Polar(p3, pi / 2 - k, b);
            Vector2 p7 = fun.Polar(p2, pi / 2 - k, b);
            Vector2 p81 = new Vector2(p0.X + b, p0.Y - 0.9 * lf);
            Vector2 p8 = fun.Inters(p81, fun.Polar(p81, 0.5 * pi, 0.8 * lf), p7, fun.Polar(p7, 1 * pi - k, 0.5 * lf));
            Vector2 p9 = new Vector2(p8.X, p0.Y - 0.1 * lf - h);
            Vector2 p10 = new Vector2(p9.X, p9.Y + h);
            Vector2 p11 = new Vector2(p9.X, p0.Y);
            Vector2 p12 = new Vector2(p0.X, p10.Y);
            Vector2 p13 = new Vector2(p0.X, p9.Y);

            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p8));
            poly.Vertexes.Add(new LwPolylineVertex(p9));
            poly.Vertexes.Add(new LwPolylineVertex(p10));
            poly.Vertexes.Add(new LwPolylineVertex(p11));
            poly.Vertexes.Add(new LwPolylineVertex(p0));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly, 0.3, contour);  // dxf文件 多段线的名字 线宽 颜色

            Vector2[] xiline1 = { p7, p2 };
            fun.drawPlineOfw(dxf, xiline1, 0.15, additionalline);  //dxf文件 线段名字 线宽 颜色
            Vector2[] xiline2 = { new Vector2((p3.X + p4.X) / 2, (p3.Y + p4.Y) / 2), new Vector2((p5.X + p6.X) / 2, (p6.Y + p5.Y) / 2) };
            fun.drawPlineOfw(dxf, xiline2, fun.CalDistance(p3, p4), additionalline);

            Vector2[] dotline1 = { p10, p12, p13, p9 };
            fun.drawPlinetype(dxf, dotline1, 0.15, contour, Linetype.DashDot);

            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p10));
            poly3.Vertexes.Add(new LwPolylineVertex(p9));
            poly3.Vertexes.Add(new LwPolylineVertex(p13));
            poly3.Vertexes.Add(new LwPolylineVertex(p12));
            poly3.Vertexes.Add(new LwPolylineVertex(p10));
            poly3.SetConstantWidth(0.3);
            poly3.IsClosed = true;

            String[] type = new String[100];
            Line[] line = new Line[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, type, numst, 5, 12, line, hatching);  //  dxf type numst 填充线段的间距 填充线段的角度 line 图层颜色
                                                                          //fun.PolyFill(dxf, poly3, 0.15, contour);           

            //标注 箭头参数
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 5;
            //标注
            LinearDimension dim1 = new LinearDimension(new Line(p13, p12), offset * 1, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim1, h);

            LinearDimension dim2 = new LinearDimension(new Line(p0, p4), offset * 2.5, 90, dimensionStyle);
            dim2.UserText = String.Format("{0}", lf);
            dxf.AddEntity(dim2);

            LinearDimension dim3 = new LinearDimension(new Line(p11, p0), offset, 0, dimensionStyle);
            dim3.UserText = String.Format("{0}", b);
            dxf.AddEntity(dim3);

            LinearDimension dim4 = new LinearDimension(new Line(p5, p1), offset * 2, 180, dimensionStyle);
            dim4.UserText = String.Format("{0}", wf);
            dxf.AddEntity(dim4);

            Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(p5, p4), new Line(p5, fun.Polar(p5, 1.5 * pi, 70)), offset * 1, dimensionStyle);
            fun.dxfangdim(dxf, angdim1, kapr);

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void TurningToolNo4StraightGroovingDesign(Dictionary<string, Object> data)        //4号车刀弯曲设计
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            double pi = Math.PI;

            //double lf = 50.0; //Convert.ToDouble(data["lf"]);
            //double cw = 6.0; //Convert.ToDouble(data["cw"]);
            //double h = 8; //Convert.ToDouble(data["h"]);
            //double b = 5.0; //Convert.ToDouble(data["b"]);
            //double rar = 5.0; //Convert.ToDouble(data["rar"]);
            //double ral = 5.0; //Convert.ToDouble(data["ral"]);
            //double cdx = 10.0; //Convert.ToDouble(data["rar"]);
            //double hea = 75.0; //Convert.ToDouble(data["hea"]);
            //string path = "E:\\dxfp\\TurningToolNo4StraightGroovingDesign.dxf"; // Convert.ToString(data["path"]);

            double lf = Convert.ToDouble(data["lf"]);
            double cw = Convert.ToDouble(data["cw"]);
            double h = Convert.ToDouble(data["h"]);
            double b = Convert.ToDouble(data["b"]);
            double rar = Convert.ToDouble(data["rar"]);
            double ral = Convert.ToDouble(data["ral"]);
            double cdx = Convert.ToDouble(data["rar"]);
            double hea = Convert.ToDouble(data["hea"]);
            string path = Convert.ToString(data["path"]);

            double r = rar * pi / 180;
            double l = rar * pi / 180;
            double he = hea * pi / 180;
            Vector2 p00 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 p0 = new Vector2(-b / 2, 0);
            Vector2 p3 = new Vector2(p00.X - cw / 2, p0.Y - lf);
            Vector2 p4 = new Vector2(-p3.X, p3.Y);
            Vector2 p1 = new Vector2(p0.X, p0.Y - lf + cdx);
            Vector2 p6 = new Vector2(-p1.X, p1.Y);
            Vector2 p2 = fun.Inters(p1, fun.Polar(p1, 1.5 * pi + he, lf), p3, fun.Polar(p3, pi / 2 - l, lf));
            Vector2 p5 = fun.Inters(p6, fun.Polar(p6, 1.5 * pi - he, lf), p4, fun.Polar(p4, pi / 2 + r, lf));
            Vector2 p7 = new Vector2(-p0.X, p0.Y);
            Vector2 p10 = new Vector2(p7.X, p7.Y - 0.1 * lf);
            Vector2 p9 = new Vector2(p10.X, p10.Y - h);
            Vector2 p12 = new Vector2(-p10.X, p10.Y);
            Vector2 p13 = new Vector2(p12.X, p12.Y - h);

            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p0));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly, 0.3, contour);  // dxf文件 多段线的名字 线宽 颜色

            Vector2 p14 = fun.Polar(p3, pi / 2 - l, cdx * 0.65);
            Vector2 p15 = fun.Polar(p4, pi / 2 + r, cdx * 0.65);
            Vector2 p16 = fun.Polar(p3, pi / 2 - l, cdx * 0.5);
            Vector2 p17 = fun.Polar(p4, pi / 2 + r, cdx * 0.5);

            Vector2[] xiline1 = { p14, p15 };
            fun.drawPlineOfw(dxf, xiline1, 0.3, additionalline);  //dxf文件 线段名字 线宽 颜色

            Solid s1 = new Solid(p3, p16, p4);
            dxf.AddEntity(s1);
            Solid s2 = new Solid(p17, p16, p4);
            dxf.AddEntity(s2);

            Vector2[] dotline1 = { p12, p10, p9, p13 };
            fun.drawPlinetype(dxf, dotline1, 0.15, contour, Linetype.DashDot);

            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p12));
            poly3.Vertexes.Add(new LwPolylineVertex(p10));
            poly3.Vertexes.Add(new LwPolylineVertex(p9));
            poly3.Vertexes.Add(new LwPolylineVertex(p13));
            poly3.Vertexes.Add(new LwPolylineVertex(p12));
            poly3.SetConstantWidth(0.3);
            poly3.IsClosed = true;

            String[] type = new String[100];
            Line[] line = new Line[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, type, numst, 5, 12, line, hatching);  //  dxf type numst 填充线段的间距 填充线段的角度 line 图层颜色
            //fun.PolyFill(dxf, poly3, 0.15, contour);

            //标注 箭头参数
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 5;
            //标注
            // LinearDimension dim1 = new LinearDimension(new Line(p10, p9), offset * 1, 90, dimensionStyle);
            //fun.dxflinedim(dxf, dim1, h);

            LinearDimension dim5 = new LinearDimension(new Line(p4, p6), offset * 1, 270, dimensionStyle);
            fun.dxflinedim(dxf, dim5, cdx);

            LinearDimension dim6 = new LinearDimension(new Line(p13, p12), offset * 1, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim6, h);

            LinearDimension dim2 = new LinearDimension(new Line(p7, p4), offset * 2, 270, dimensionStyle);
            dim2.UserText = String.Format("{0}", lf);
            dxf.AddEntity(dim2);

            LinearDimension dim3 = new LinearDimension(new Line(p7, p0), offset, 0, dimensionStyle);
            dim3.UserText = String.Format("{0}", b);
            dxf.AddEntity(dim3);

            LinearDimension dim4 = new LinearDimension(new Line(p4, p3), offset * 1, 180, dimensionStyle);
            dim4.UserText = String.Format("{0}", cw);
            dxf.AddEntity(dim4);

            Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(p3, p2), new Line(p3, fun.Polar(p3, 0.5 * pi, 70)), offset * 3, dimensionStyle);
            fun.dxfangdim(dxf, angdim1, ral);

            Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(p4, p5), new Line(p4, fun.Polar(p4, 0.5 * pi, 70)), offset * 3, dimensionStyle);
            fun.dxfangdim(dxf, angdim2, rar);

            Angular2LineDimension angdim3 = new Angular2LineDimension(new Line(p1, fun.Polar(p1, pi / 2, 70)), new Line(p2, fun.Polar(p2, pi / 2 + he, 70)), offset * (2.5), dimensionStyle);
            fun.dxfangdim(dxf, angdim3, hea);

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void TurningToolNo7GroovingAndCutOffDesign(Dictionary<string, Object> data)        //4号车刀弯曲设计
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            double pi = Math.PI;

            //double lf = 60.0; //Convert.ToDouble(data["lf"]);
            //double cw = 4.0; //Convert.ToDouble(data["cw"]);
            //double wf = 14.0; //Convert.ToDouble(data["wf"]);
            //double h = 8; //Convert.ToDouble(data["h"]);
            //double b = 15.0; //Convert.ToDouble(data["b"]);
            //double rar = 5.0; //Convert.ToDouble(data["rar"]);
            //double ral = 5.0; //Convert.ToDouble(data["ral"]);
            //double cdx = 10.0; //Convert.ToDouble(data["cdx"]);
            //double hea = 55.0; //Convert.ToDouble(data["hea"]);
            //string path = "E:\\dxfp\\TurningToolNo7GroovingAndCutOffDesign.dxf"; // Convert.ToString(data["path"]);

            double lf = Convert.ToDouble(data["lf"]);
            double cw = Convert.ToDouble(data["cw"]);
            double wf = Convert.ToDouble(data["wf"]);
            double h = Convert.ToDouble(data["h"]);
            double b = Convert.ToDouble(data["b"]);
            double rar = Convert.ToDouble(data["rar"]);
            double ral = Convert.ToDouble(data["ral"]);
            double cdx = Convert.ToDouble(data["cdx"]);
            double hea = Convert.ToDouble(data["hea"]);
            string path = Convert.ToString(data["path"]);

            double r = rar * pi / 180;
            double l = rar * pi / 180;
            double he = hea * pi / 180;
            Vector2 p00 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 p1 = new Vector2(0, 0);
            Vector2 p15 = new Vector2(p1.X + b, p1.Y);
            Vector2 p2 = new Vector2(p1.X, p1.Y - 0.1 * lf);
            Vector2 p3 = new Vector2(p2.X, p2.Y - h);
            Vector2 p9 = new Vector2(p1.X + wf, p1.Y - lf);
            Vector2 p8 = new Vector2(p9.X - cw, p9.Y);
            Vector2 p6 = fun.Polar(p8, pi / 2 - l, 0.9 * cdx);
            Vector2 p7 = fun.Polar(p8, pi / 2 - l, 0.5 * cdx);
            Vector2 p5 = fun.Polar(p6, pi / 2 + he, (p6.X - p8.X) / Math.Cos(pi / 2 - he));
            Vector2 p4 = fun.Inters(p6, fun.Polar(p6, pi / 2 + he, 100), p1, fun.Polar(p1, pi * 1.5, 100));
            Vector2 p10 = fun.Polar(p9, pi / 2 + r, 0.5 * cdx);
            Vector2 p11 = fun.Polar(p9, pi / 2 + r, 0.9 * cdx);
            Vector2 p12 = fun.Inters(p11, fun.Polar(p11, pi / 2 - he, 100), p15, fun.Polar(p15, pi * 1.5, 100));
            Vector2 p13 = new Vector2(p15.X, p3.Y);
            Vector2 p14 = new Vector2(p15.X, p2.Y);

            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p8));
            poly.Vertexes.Add(new LwPolylineVertex(p9));
            poly.Vertexes.Add(new LwPolylineVertex(p10));
            poly.Vertexes.Add(new LwPolylineVertex(p11));
            poly.Vertexes.Add(new LwPolylineVertex(p12));
            poly.Vertexes.Add(new LwPolylineVertex(p13));
            poly.Vertexes.Add(new LwPolylineVertex(p14));
            poly.Vertexes.Add(new LwPolylineVertex(p15));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly, 0.3, contour);  // dxf文件 多段线的名字 线宽

            Vector2[] xiline1 = { p11, p6 };
            fun.drawPlineOfw(dxf, xiline1, 0.3, additionalline);  //  dxf文件 线段名字 线宽 颜色                                     

            Solid s1 = new Solid(p7, p10, p8);
            dxf.AddEntity(s1);
            Solid s2 = new Solid(p8, p9, p10);
            dxf.AddEntity(s2);

            Vector2[] dotline1 = { p2, p14, p13, p3 };
            fun.drawPlinetype(dxf, dotline1, 0.15, contour, Linetype.DashDot);

            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p2));
            poly3.Vertexes.Add(new LwPolylineVertex(p3));
            poly3.Vertexes.Add(new LwPolylineVertex(p13));
            poly3.Vertexes.Add(new LwPolylineVertex(p14));
            poly3.Vertexes.Add(new LwPolylineVertex(p2));
            poly3.SetConstantWidth(0.3);
            poly3.IsClosed = true;

            String[] type = new String[100];
            Line[] line = new Line[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, type, numst, 5, 12, line, hatching);  //  dxf type numst 填充线段的间距 填充线段的角度 line 图层颜色
                                                                          // fun.PolyFill(dxf, poly3, 0.15, contour);

            //标注 箭头参数
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            //标注
            // LinearDimension dim1 = new LinearDimension(new Line(p10, p9), offset * 1, 90, dimensionStyle);
            //fun.dxflinedim(dxf, dim1, h);

            LinearDimension dim5 = new LinearDimension(new Line(p8, p5), offset * 2, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim5, cdx);

            LinearDimension dim6 = new LinearDimension(new Line(p3, p2), offset * 1, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim6, h);

            LinearDimension dim7 = new LinearDimension(new Line(p4, p9), offset * 3, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim7, wf);

            LinearDimension dim2 = new LinearDimension(new Line(p15, p9), offset * 1, 270, dimensionStyle);
            dim2.UserText = String.Format("{0}", lf);
            dxf.AddEntity(dim2);

            LinearDimension dim3 = new LinearDimension(new Line(p1, p15), offset, 0, dimensionStyle);
            dim3.UserText = String.Format("{0}", b);
            dxf.AddEntity(dim3);

            LinearDimension dim4 = new LinearDimension(new Line(p8, p9), offset * 1, 180, dimensionStyle);
            dim4.UserText = String.Format("{0}", cw);
            dxf.AddEntity(dim4);

            Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(p4, fun.Polar(p4, 1.5 * pi + he, 70)), new Line(p4, fun.Polar(p4, 1.5 * pi, 70)), offset * 0.5, dimensionStyle);
            fun.dxfangdim(dxf, angdim1, hea);

            Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(p8, p6), new Line(p8, fun.Polar(p8, 0.5 * pi, 70)), offset * 2, dimensionStyle);
            fun.dxfangdim(dxf, angdim2, rar);

            Angular2LineDimension angdim3 = new Angular2LineDimension(new Line(p9, p11), new Line(p9, fun.Polar(p9, pi / 2, 70)), offset * 2, dimensionStyle);
            fun.dxfangdim(dxf, angdim3, ral);

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void TurningToolPointedStraightDesign(Dictionary<string, Object> data)        //车刀-尖刀直切设计
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    // 非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            double pi = Math.PI;

            //double lf = 60.0; //Convert.ToDouble(data["lf"]);
            //double l = 4.0; //Convert.ToDouble(data["l"]);
            //double wf = 5.0; //Convert.ToDouble(data["wf"]);
            //double h = 6; //Convert.ToDouble(data["h"]);
            //double b = 10.0; //Convert.ToDouble(data["b"]);
            //double kpar = 60.0; //Convert.ToDouble(data["kpar"]);
            //double epsr = 60.0; //Convert.ToDouble(data["epsr"]);
            //double lh = 12.0; //Convert.ToDouble(data["lh"]);
            //string path = "E:\\dxfp\\TurningToolPointedStraightDesign.dxf"; // Convert.ToString(data["path"]);

            double lf = Convert.ToDouble(data["lf"]);
            double l = Convert.ToDouble(data["l"]);
            double wf = Convert.ToDouble(data["wf"]);
            double h = Convert.ToDouble(data["h"]);
            double b = Convert.ToDouble(data["b"]);
            double kpar = Convert.ToDouble(data["kpar"]);
            double epsr = Convert.ToDouble(data["epsr"]);
            double lh = Convert.ToDouble(data["lh"]);
            string path = Convert.ToString(data["path"]);

            double k = kpar * pi / 180;//
            double e = epsr * pi / 180;
            Vector2 p00 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 p1 = new Vector2(p00.X - b / 2, 0);
            Vector2 p2 = new Vector2(p1.X, p1.Y - 0.1 * lf);
            Vector2 p3 = new Vector2(p2.X, p2.Y - h);
            Vector2 p8 = new Vector2(p1.X + wf, p00.Y - lf);
            Vector2 p4 = new Vector2(p3.X, p8.Y + lh);
            Vector2 p5 = new Vector2(p4.X, p4.Y - 0.15 * lh);
            Vector2 p6 = fun.Inters(p8, fun.Polar(p8, pi - k, 100), p1, fun.Polar(p1, 1.5 * pi, 100));
            Vector2 p7 = fun.Polar(p8, pi - k, 0.5 * l / Math.Cos(k));
            Vector2 p7p = new Vector2(-p7.X, p7.Y);
            Vector2 p6p = new Vector2(-p6.X, p6.Y);
            Vector2 p5p = new Vector2(-p5.X, p5.Y);
            Vector2 p4p = new Vector2(-p4.X, p4.Y);
            Vector2 p3p = new Vector2(-p3.X, p3.Y);
            Vector2 p2p = new Vector2(-p2.X, p2.Y);
            Vector2 p1p = new Vector2(-p1.X, p1.Y);

            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p8));
            poly.Vertexes.Add(new LwPolylineVertex(p7p));
            poly.Vertexes.Add(new LwPolylineVertex(p6p));
            poly.Vertexes.Add(new LwPolylineVertex(p5p));
            poly.Vertexes.Add(new LwPolylineVertex(p4p));
            poly.Vertexes.Add(new LwPolylineVertex(p3p));
            poly.Vertexes.Add(new LwPolylineVertex(p2p));
            poly.Vertexes.Add(new LwPolylineVertex(p1p));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly, 0.3, contour);  // dxf文件 多段线的名字 线宽

            Vector2[] xiline1 = { p4, p4p };
            fun.drawPlineOfw(dxf, xiline1, 0.3, additionalline);  //  dxf文件 线段名字 线宽 颜色                                     
            Vector2[] xiline2 = { p5, p5p };
            fun.drawPlineOfw(dxf, xiline2, 0.3, additionalline);

            Vector2 p9 = new Vector2(p7.X, p5.Y);
            Vector2 p9p = new Vector2(-p9.X, p9.Y);

            Solid s1 = new Solid(p7, p7p, p8);
            dxf.AddEntity(s1);
            Solid s2 = new Solid(p7, p9, p9p);
            dxf.AddEntity(s2);
            Solid s3 = new Solid(p7, p9p, p7p);
            dxf.AddEntity(s3);

            Vector2[] dotline1 = { p2, p2p, p3p, p3 };
            fun.drawPlinetype(dxf, dotline1, 0.15, contour, Linetype.DashDot);

            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p2));
            poly3.Vertexes.Add(new LwPolylineVertex(p3));
            poly3.Vertexes.Add(new LwPolylineVertex(p3p));
            poly3.Vertexes.Add(new LwPolylineVertex(p2p));
            poly3.Vertexes.Add(new LwPolylineVertex(p2));
            poly3.SetConstantWidth(0.3);
            poly3.IsClosed = true;

            String[] type = new String[100];
            Line[] line = new Line[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, type, numst, 5, 12, line, hatching);  //  dxf type numst 填充线段的间距 填充线段的角度 line 图层颜色
            //fun.PolyFill(dxf, poly3, 0.15, contour);
            //fun.PolyFillandlinetype(dxf, poly3, 0.15,contour , Linetype.DashDot);

            //标注 箭头参数
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            //标注
            // LinearDimension dim1 = new LinearDimension(new Line(p10, p9), offset * 1, 90, dimensionStyle);
            //fun.dxflinedim(dxf, dim1, h);

            LinearDimension dim5 = new LinearDimension(new Line(p8, p4), offset * 2, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim5, lh);

            LinearDimension dim6 = new LinearDimension(new Line(p3, p2), offset * 1, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim6, h);

            LinearDimension dim7 = new LinearDimension(new Line(p8, p6), offset * 3, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim7, wf);

            LinearDimension dim2 = new LinearDimension(new Line(p1p, p8), offset * 1, 270, dimensionStyle);
            dim2.UserText = String.Format("{0}", lf);
            dxf.AddEntity(dim2);

            LinearDimension dim3 = new LinearDimension(new Line(p1, p1p), offset, 0, dimensionStyle);
            dim3.UserText = String.Format("{0}", b);
            dxf.AddEntity(dim3);

            LinearDimension dim4 = new LinearDimension(new Line(p7, p7p), offset * 2, 180, dimensionStyle);
            dim4.UserText = String.Format("{0}", l);
            dxf.AddEntity(dim4);

            Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(p8, p6), new Line(p8, p7p), offset * 2, dimensionStyle);
            fun.dxfangdim(dxf, angdim1, epsr);

            Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(p8, p6), new Line(p8, fun.Polar(p8, 1 * pi, 70)), offset * 2, dimensionStyle);
            fun.dxfangdim(dxf, angdim2, kpar);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}

